/**
 * Copyright ©2016-2020 northkingbpo Corporation, All Rights Reserved
 * http://www.northkingbpo.net/
 */
package profile.hujia.spring.cloud.stream.kafka.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import profile.hujia.spring.cloud.stream.kafka.domain.People;
import profile.hujia.spring.cloud.stream.kafka.server.SendMessage;

/**
 * class info
 *
 * @author hujia
 * @date 2019-03-25 10:29
 */
@RestController
@RequestMapping
public class KafkaController {

    private final ObjectMapper jackson;
    private final SendMessage sendMessage;

    @Autowired
    public KafkaController(ObjectMapper jackson, SendMessage sendMessage) {
        this.jackson = jackson;
        this.sendMessage = sendMessage;
    }

    @PostMapping("/send")
    public String addPeople(@RequestBody People people) throws Exception {
        String message = jackson.writeValueAsString(people);
        this.sendMessage.send(message);
        return "ok";
    }
}
